package com.sywb.chuangyebao.contract;

import android.app.Activity;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.sywb.chuangyebao.Constants;
import com.sywb.chuangyebao.R;
import com.sywb.chuangyebao.bean.ChatSession;
import com.sywb.chuangyebao.bean.NewsOwner;
import com.sywb.chuangyebao.bean.Notice;
import com.sywb.chuangyebao.bean.NotificationInfo;
import com.sywb.chuangyebao.utils.GlideUtils;
import com.sywb.chuangyebao.utils.HttpCallback;
import com.sywb.chuangyebao.utils.HttpUtils;
import com.sywb.chuangyebao.utils.Utils;
import com.sywb.chuangyebao.view.AnswerDetailActivity;
import com.sywb.chuangyebao.view.NewsDetailActivity;
import com.sywb.chuangyebao.view.QAndADetailActivity;
import com.sywb.chuangyebao.view.TopicActivity;
import com.sywb.chuangyebao.view.UserChatActivity;
import com.sywb.chuangyebao.view.UserMessageActivity;
import com.sywb.chuangyebao.view.UserNoticeDetailActivity;
import com.sywb.chuangyebao.view.VideoDetailActivity;
import com.sywb.chuangyebao.widget.RichTextView;

import org.bining.footstone.adapter.BasePagerAdapter;
import org.bining.footstone.adapter.BaseRecyclerAdapter;
import org.bining.footstone.adapter.BaseRecyclerDivider;
import org.bining.footstone.adapter.ViewHolderHelper;
import org.bining.footstone.adapter.listener.OnItemChildClickListener;
import org.bining.footstone.adapter.listener.OnItemClickListener;
import org.bining.footstone.adapter.listener.OnLoadMoreListener;
import org.bining.footstone.db.DbManager;
import org.bining.footstone.db.assit.QueryBuilder;
import org.bining.footstone.log.Logger;
import org.bining.footstone.mvp.IView;
import org.bining.footstone.presenter.BasePresenter;
import org.bining.footstone.rxjava.rxbus.RxBus;
import org.bining.footstone.utils.ScreenUtils;
import org.bining.footstone.utils.SharedUtils;
import org.bining.footstone.utils.TimeUtils;
import org.bining.footstone.view.BaseActivity;
import org.bining.footstone.widget.PullToRefreshView;

import java.util.ArrayList;
import java.util.List;

public interface UserMessageContract {

    interface MessageView extends IView {

        ViewPager getViewPager();

        View getTabCursor();

        void setMesssageUnread(int notificationCount, int letterCount, int noticeCount);
    }

    class Presenter extends BasePresenter<MessageView> {

        private ViewPager viewPager;
        private android.view.View tabCursor;

        private List<PullToRefreshView> commonRefreshs;
        private List<RecyclerView> commonRecyclers;
        private List<RelativeLayout> commonNoDatas;
        private List<BaseRecyclerAdapter> adapters;
        private int[] pageNos;

        private int tabChildWidth;
        private int currentIndex;

        @Override
        public void onStart() {
            this.viewPager = mView.getViewPager();
            this.tabCursor = mView.getTabCursor();

            commonRefreshs = new ArrayList<>();
            commonRecyclers = new ArrayList<>();
            commonNoDatas = new ArrayList<>();
            adapters = new ArrayList<>();
            pageNos = new int[]{
                    1, 1, 1
            };

            List<android.view.View> viewList = new ArrayList<>();
            viewList.add(initWaitPassMsgPage(0));
            viewList.add(initWaitPassMsgPage(1));
            viewList.add(initWaitPassMsgPage(2));

            this.viewPager.setAdapter(new BasePagerAdapter(viewList));
            this.viewPager.setOffscreenPageLimit(viewList.size());
            this.viewPager.setCurrentItem(0);

            initTabWidth();
        }

        /**
         * 初始化View
         */
        private android.view.View initWaitPassMsgPage(final int type) {
            android.view.View view = mActivity.getLayoutInflater().inflate(R.layout.layout_recycler_refresh, null);
            PullToRefreshView commonRefresh = view.findViewById(R.id.common_refresh);
            RecyclerView commonRecycler = view.findViewById(R.id.common_recycler);
            RelativeLayout commonNoData = view.findViewById(R.id.common_nodata);
            commonRefreshs.add(commonRefresh);
            commonRecyclers.add(commonRecycler);
            commonNoDatas.add(commonNoData);

            commonRecycler.setLayoutManager(new LinearLayoutManager(mActivity));

            BaseRecyclerDivider divider = new BaseRecyclerDivider();
            divider.setDivider(0);
            commonRecycler.addItemDecoration(divider);

            switch (type) {
                case 0:
                    commonRefresh.setOnRefreshListener(new PullToRefreshView.OnRefreshListener() {
                        @Override
                        public void onRefresh(PullToRefreshView pullToRefreshView) {
                            pageNos[0] = 1;
                            getMyNote();
                        }
                    });

                    NotificationAdapter notificationAdapter = new NotificationAdapter(mActivity);
                    notificationAdapter.setOnItemClickListener(new OnItemClickListener() {
                        @Override
                        public void onItemClick(android.view.View view, int i) {
                            if (!((BaseActivity) mActivity).isCanClick(view)) return;
                            RxBus.get().post(Constants.USERCHAT, Constants.USERCHAT);
                            NotificationInfo notificationInfo = (NotificationInfo) adapters.get(0).getItem(i);
                            if (notificationInfo.topic.topic_type.equals("article")) {
                                mView.advance(NewsDetailActivity.class, notificationInfo.topic.topic_id);
                            } else if (notificationInfo.topic.topic_type.equals("question")) {
                                mView.advance(QAndADetailActivity.class, notificationInfo.topic.topic_id);
                            } else if (notificationInfo.topic.topic_type.equals("answer")) {
                                mView.advance(AnswerDetailActivity.class, notificationInfo.topic.topic_id);
                            } else if (notificationInfo.topic.topic_type.equals("video")) {
                                mView.advance(VideoDetailActivity.class, notificationInfo.topic.topic_id);
                            }
                        }
                    });
                    notificationAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
                        @Override
                        public void onItemChildClick(View view, int i) {
                            if (!((BaseActivity) mActivity).isCanClick(view)) return;
                            NotificationInfo notificationInfo = (NotificationInfo) adapters.get(0).getItem(i);
                            switch (view.getId()) {
                                case R.id.iv_face:
                                case R.id.iv_user_type:
                                case R.id.tv_collection_name:
//                                    mView.advance(UserIndexActivity.class, notificationInfo.owner.uid);
                                    Utils.goUserIndex(mView, notificationInfo.owner.uid);
                                    break;
                                case R.id.ll_qustion:
                                    if (notificationInfo.topic.topic_type.equals("article")) {
                                        mView.advance(NewsDetailActivity.class, notificationInfo.topic.topic_id);
                                    } else if (notificationInfo.topic.topic_type.equals("question")) {
                                        mView.advance(QAndADetailActivity.class, notificationInfo.topic.topic_id);
                                    } else if (notificationInfo.topic.topic_type.equals("answer")) {
                                        mView.advance(AnswerDetailActivity.class, notificationInfo.topic.topic_id);
                                    } else if (notificationInfo.topic.topic_type.equals("video")) {
                                        mView.advance(VideoDetailActivity.class, notificationInfo.topic.topic_id);
                                    }
                                    break;
                            }
                        }
                    });

                    notificationAdapter.openLoadMore(R.layout.layout_loading, Constants.PAGESIZE);
                    notificationAdapter.setOnLoadMoreListener(new OnLoadMoreListener() {
                        @Override
                        public void onLoadMoreClick() {
                            pageNos[0]++;
                            getMyNote();
                        }
                    });

                    commonRecycler.setAdapter(notificationAdapter);
                    adapters.add(notificationAdapter);

                    onStartAsync();
                    getMyNote();
                    break;
                case 1:
                    commonRefresh.setOnRefreshListener(new PullToRefreshView.OnRefreshListener() {
                        @Override
                        public void onRefresh(PullToRefreshView pullToRefreshView) {
                            getChatConect();
                        }
                    });

                    FriendAdapter friendAdapter = new FriendAdapter(mActivity);
                    friendAdapter.setOnItemClickListener(new OnItemClickListener() {
                        @Override
                        public void onItemClick(android.view.View view, int i) {
                            if (!((BaseActivity) mActivity).isCanClick(view)) return;
                            ChatSession chatSession = (ChatSession) adapters.get(1).getItem(i);
                            if (chatSession.status == 2) {
                                chatSession.status = 1;
                                DbManager.getInstance().save(chatSession);
                            }
                            mView.advance(UserChatActivity.class, chatSession.session_uid, chatSession.owner);
                        }
                    });
                    commonRecycler.setAdapter(friendAdapter);
                    adapters.add(friendAdapter);

                    initChatData();
                    onStartAsync();
                    getChatConect();
                    break;
                case 2:
                    commonRefresh.setOnRefreshListener(new PullToRefreshView.OnRefreshListener() {
                        @Override
                        public void onRefresh(PullToRefreshView pullToRefreshView) {
                            refreshNotices();
                        }
                    });

                    final NoticeAdapter noticeAdapter = new NoticeAdapter(mActivity);
                    noticeAdapter.setOnItemClickListener(new OnItemClickListener() {
                        @Override
                        public void onItemClick(android.view.View view, int i) {
                            if (!((BaseActivity) mActivity).isCanClick(view)) return;
                            Notice notice = (Notice) adapters.get(2).getItem(i);
                            mView.advance(UserNoticeDetailActivity.class, JSON.toJSONString(notice));

                            if (!notice.is_read) {
                                notice.is_read = true;
                                noticeAdapter.notifyDataSetChanged();
                            }
                        }
                    });

                    noticeAdapter.openLoadMore(R.layout.layout_loading, Constants.PAGESIZE);
                    noticeAdapter.setOnLoadMoreListener(new OnLoadMoreListener() {
                        @Override
                        public void onLoadMoreClick() {
                            pageNos[2]++;
                            getNotices();
                        }
                    });

                    commonRecycler.setAdapter(noticeAdapter);
                    adapters.add(noticeAdapter);

                    onStartAsync();
                    getNotices();
                    break;
            }

            isNoData(type);

            return view;
        }

        /**
         * 初始化指示条宽度
         */
        private void initTabWidth() {
            this.tabChildWidth = ScreenUtils.getScreenWidth() / 3;
            int cursorTextWidth = tabChildWidth;
            ViewGroup.MarginLayoutParams p1 = (ViewGroup.MarginLayoutParams) this.tabCursor.getLayoutParams();
            p1.width = cursorTextWidth;
            this.tabCursor.requestLayout();
        }

        /**
         * 切换Tab视图
         *
         * @param position 切换位置
         */
        public void changeView(int position, TextView tvNotification, TextView tvLetter, TextView tvNotice) {
            if (position == currentIndex) {
                return;
            }
            int fromXDelta = tabChildWidth * viewPager.getCurrentItem();
            int toXDelta = tabChildWidth * position;
            TranslateAnimation animation = new TranslateAnimation((float) fromXDelta, (float) toXDelta, 0.0F, 0.0F);
            animation.setFillAfter(true);
            animation.setDuration(500L);
            this.tabCursor.startAnimation(animation);

            switch (currentIndex) {
                case 0:
                    tvNotification.setTextColor(ContextCompat.getColor(mActivity, R.color.colorDark));
                    break;
                case 1:
                    tvLetter.setTextColor(ContextCompat.getColor(mActivity, R.color.colorDark));
                    break;
                case 2:
                    tvNotice.setTextColor(ContextCompat.getColor(mActivity, R.color.colorDark));
                    break;
            }

            switch (position) {
                case 0:
                    tvNotification.setTextColor(ContextCompat.getColor(mActivity, R.color.colorTheme));
                    break;
                case 1:
                    tvLetter.setTextColor(ContextCompat.getColor(mActivity, R.color.colorTheme));
                    break;
                case 2:
                    tvNotice.setTextColor(ContextCompat.getColor(mActivity, R.color.colorTheme));
                    break;
            }

            viewPager.setCurrentItem(position);
            currentIndex = position;
        }

        public void getMyNote() {
            HttpUtils.getMyNote(pageNos[0], new HttpCallback<List<NotificationInfo>>() {
                @Override
                public void onSuccess(List<NotificationInfo> superInfos) {
                    if (pageNos[0] == 1) {
                        onEndRefresh(0);
                        adapters.get(0).clearDatas();
                    } else {
                        onEndLoadMore(0);
                    }
                    if (superInfos != null) {
                        adapters.get(0).notifyDataChangedAfterLoadMore(superInfos);
                    }
                }

                @Override
                public void onError(String strMsg) {
                    super.onError(strMsg);
                    if (pageNos[0] == 1) {
                        onEndRefresh(0);
                    } else {
                        onEndLoadMore(0);
                    }
                    showMessage(strMsg);
                }

                @Override
                public void onFinish() {
                    super.onFinish();
                    onFinishAsync();
                    isNoData(0);
                }
            });
        }

        public void getChatConect() {
            HttpUtils.chatConcat(new HttpCallback<List<ChatSession>>() {
                @Override
                public void onSuccess(List<ChatSession> chatSessions) {
                    if (pageNos[1] == 1) {
                        onEndRefresh(1);
                    } else {
                        onEndLoadMore(1);
                    }
                    for (ChatSession chatSession : chatSessions) {
                        if (chatSession.from_uid == chatSession.getOwner().uid) {
                            chatSession.session_uid = chatSession.from_uid;
                            chatSession.my_uid = chatSession.to_uid;
                        } else {
                            chatSession.session_uid = chatSession.to_uid;
                            chatSession.my_uid = chatSession.from_uid;
                        }
                    }
//                    DbManager.getInstance().deleteAll(ChatSession.class);
                    DbManager.getInstance().save(chatSessions);
                }

                @Override
                public void onError(String strMsg) {
                    super.onError(strMsg);
                    if (pageNos[1] == 1) {
                        onEndRefresh(1);
                    } else {
                        onEndLoadMore(1);
                    }
                    showMessage(strMsg);
                }

                @Override
                public void onFinish() {
                    super.onFinish();
                    onFinishAsync();
                }
            });
        }

        public void initChatData() {
            List<ChatSession> chatSessions = DbManager.getInstance().query(QueryBuilder.create(ChatSession.class).where("my_uid = ?", SharedUtils.getString(Constants.USEROPENID)).appendOrderDescBy("create_time"));
            Logger.e("initChatData:" + JSON.toJSONString(chatSessions));
            adapters.get(1).setDatas(chatSessions);
            isNoData(1);
        }

        public void refreshNotices() {
            pageNos[2] = 1;
            getNotices();
        }

        private void getNotices() {
            HttpUtils.listNotice(pageNos[2], new HttpCallback<List<Notice>>() {

                @Override
                public void onSuccess(List<Notice> notices) {
                    if (pageNos[2] == 1) {
                        onEndRefresh(2);
                        adapters.get(2).clearDatas();
                    } else {
                        onEndLoadMore(2);
                    }
                    if (notices != null) {
                        adapters.get(2).notifyDataChangedAfterLoadMore(notices);
                    }
                }

                @Override
                public void onError(String strMsg) {
                    super.onError(strMsg);
                    if (pageNos[2] == 1) {
                        onEndRefresh(2);
                    } else {
                        onEndLoadMore(2);
                    }
                    showMessage(strMsg);
                }

                @Override
                public void onFinish() {
                    super.onFinish();
                    onFinishAsync();
                    isNoData(2);
                }

            });
        }

        private void onEndRefresh(int currentItem) {
            commonRefreshs.get(currentItem).refreshFinish(true);
        }

        private void onEndLoadMore(int currentItem) {
            commonRefreshs.get(currentItem).loadmoreFinish(true);
        }

        /**
         * 设置是否有数据
         *
         * @param position 哪个视图
         */
        void isNoData(int position) {
            commonNoDatas.get(position).setVisibility(adapters.get(position).getDataCount() == 0 ? View.VISIBLE : View.GONE);
        }

        class NotificationAdapter extends BaseRecyclerAdapter<NotificationInfo> {

            NotificationAdapter(Activity activity) {
                super(activity, R.layout.item_notification);
            }

            @Override
            protected void setItemData(ViewHolderHelper viewHolderHelper, int position, NotificationInfo notificationInfo) {

                viewHolderHelper.setVisibility(R.id.tv_recommend, View.GONE);

                NewsOwner owner = notificationInfo.owner;

                ImageView imageFace = viewHolderHelper.getView(R.id.iv_face);
                if (owner != null) {
                    GlideUtils.getCircleImageToUrl(mActivity, owner.getShowAvatar(), imageFace, R.drawable.head_image);
                    viewHolderHelper.setText(R.id.tv_collection_name, owner.getShowName());

                    int userRole = owner.getUserRole();
                    if (userRole == Constants.USER_TYPE_NORMAL) {
                        viewHolderHelper.setVisibility(R.id.iv_user_type, false);
                    } else {
                        viewHolderHelper.setVisibility(R.id.iv_user_type, true);
                        switch (userRole) {
                            case Constants.USER_TYPE_V:
                                viewHolderHelper.setImageResource(R.id.iv_user_type, R.drawable.official_icon);
                                break;
                            case Constants.USER_TYPE_PROJECT:
                                viewHolderHelper.setImageResource(R.id.iv_user_type, R.drawable.icon_project);
                                break;
                            case Constants.USER_TYPE_SERVICE:
                                viewHolderHelper.setImageResource(R.id.iv_user_type, R.drawable.icon_service);
                                break;
                            case Constants.USER_TYPE_TUTOR:
                                viewHolderHelper.setImageResource(R.id.iv_user_type, R.drawable.icon_teacher);
                                break;
                        }
                    }

                    viewHolderHelper.setItemChildClickListener(R.id.iv_face);
                    viewHolderHelper.setItemChildClickListener(R.id.iv_user_type);
                    viewHolderHelper.setItemChildClickListener(R.id.tv_collection_name);
                } else {
                    imageFace.setImageResource(R.drawable.head_image);
                    viewHolderHelper.setText(R.id.tv_collection_name, "");
                    viewHolderHelper.setVisibility(R.id.iv_user_type, false);
                }

                viewHolderHelper.setVisibility(R.id.tv_operate, true);
                viewHolderHelper.setText(R.id.tv_operate, notificationInfo.content_type);
                viewHolderHelper.setText(R.id.tv_collection_time, TimeUtils.transformDate10(notificationInfo.create_time));

                if (notificationInfo.content != null) {
                    viewHolderHelper.setVisibility(R.id.richTextView, true);

                    //设置富文本
                    RichTextView richTextView = viewHolderHelper.getView(R.id.richTextView);
                    richTextView.setRichText(notificationInfo.content.content, notificationInfo.content.richInfoList);
                    richTextView.setOnLinkClickListener(new RichTextView.OnLinkClickListener() {
                        @Override
                        public void onAtClick(RichTextView richTextView, Object userId) {
//                            mView.advance(UserIndexActivity.class, userId);
                            Utils.goUserIndex(mView, (Integer) userId);
                        }

                        @Override
                        public void onTopicClick(RichTextView richTextView, Object topicId) {
                            mView.advance(TopicActivity.class, topicId);
                        }

                        @Override
                        public void onEmojiClick(RichTextView richTextView, Object emoji) {

                        }

                        @Override
                        public void onUrlClick(RichTextView richTextView, Object url) {

                        }

                        @Override
                        public void onAllClick(RichTextView richTextView) {

                        }
                    });
                } else {
                    viewHolderHelper.setVisibility(R.id.richTextView, false);
                }

                if (notificationInfo.comment != null) {
                    viewHolderHelper.setVisibility(R.id.tv_subtitile, true);
                    TextView subTitile = viewHolderHelper.getView(R.id.tv_subtitile);

                    String message = notificationInfo.comment.nickname + ":" + notificationInfo.comment.comment;

                    SpannableString spannableString = new SpannableString(message);
                    ForegroundColorSpan colorSpan = new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.colorGray));
                    spannableString.setSpan(colorSpan, 0, notificationInfo.comment.nickname.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                    subTitile.setText(spannableString);
                } else {
                    viewHolderHelper.setVisibility(R.id.tv_subtitile, false);
                }

                if (notificationInfo.topic != null) {
                    viewHolderHelper.setVisibility(R.id.ll_qustion, true);
                    boolean isMultiMedia = false;
                    if (!TextUtils.isEmpty(notificationInfo.topic.url)) {
                        viewHolderHelper.setVisibility(R.id.iv_media_type, true);
                        if (notificationInfo.topic.topic_type.equals("video")) {
                            viewHolderHelper.setImageResource(R.id.iv_media_type, R.drawable.icon_media_video);
                        } else {
                            viewHolderHelper.setImageResource(R.id.iv_media_type, R.drawable.icon_media_audio);
                        }
                        isMultiMedia = true;
                    } else {
                        viewHolderHelper.setVisibility(R.id.iv_media_type, false);
                    }

                    if (!TextUtils.isEmpty(notificationInfo.topic.pic)) {
                        viewHolderHelper.setVisibility(R.id.iv_media, true);
                        ImageView image = viewHolderHelper.getView(R.id.iv_media);
                        GlideUtils.getNormalIamgeToUrl(mActivity, notificationInfo.topic.pic, image, R.drawable.image_def);
                        isMultiMedia = true;
                    } else {
                        viewHolderHelper.setVisibility(R.id.iv_media, false);
                    }

                    if (isMultiMedia) {
                        viewHolderHelper.setVisibility(R.id.rl_media, true);
                    } else {
                        viewHolderHelper.setVisibility(R.id.rl_media, false);
                    }

                    viewHolderHelper.setText(R.id.tv_media_name, notificationInfo.topic.title);

                    viewHolderHelper.setItemChildClickListener(R.id.ll_qustion);
                } else {
                    viewHolderHelper.setVisibility(R.id.ll_qustion, false);

                }
            }
        }

        class FriendAdapter extends BaseRecyclerAdapter<ChatSession> {

            FriendAdapter(Activity activity) {
                super(activity, R.layout.item_friend);
            }

            @Override
            protected void setItemData(ViewHolderHelper viewHolderHelper, int position, ChatSession chatSession) {
                viewHolderHelper.setVisibility(R.id.notice_unread, android.view.View.VISIBLE);
                viewHolderHelper.setVisibility(R.id.tv_add_focus, android.view.View.GONE);

                ImageView imageView = viewHolderHelper.getView(R.id.iv_friend_face);

                NewsOwner newsOwner = chatSession.getOwner();
                if (newsOwner != null) {
                    GlideUtils.getCircleImageToUrl(mActivity, newsOwner.getShowAvatar(), imageView);

                    int userRole = newsOwner.getUserRole();
                    if (userRole == Constants.USER_TYPE_NORMAL) {
                        viewHolderHelper.setVisibility(R.id.iv_user_type, false);
                        viewHolderHelper.setVisibility(R.id.tv_friend_type, false);
                    } else {
                        viewHolderHelper.setVisibility(R.id.iv_user_type, true);
                        viewHolderHelper.setVisibility(R.id.tv_friend_type, true);
                        switch (newsOwner.getUserRole()) {
                            case Constants.USER_TYPE_V:
                                viewHolderHelper.setImageResource(R.id.iv_user_type, R.drawable.official_icon);
                                viewHolderHelper.setText(R.id.tv_friend_type, "官方号");
                                break;
                            case Constants.USER_TYPE_PROJECT:
                                viewHolderHelper.setImageResource(R.id.iv_user_type, R.drawable.icon_project);
                                viewHolderHelper.setText(R.id.tv_friend_type, "项目号");
                                break;
                            case Constants.USER_TYPE_SERVICE:
                                viewHolderHelper.setImageResource(R.id.iv_user_type, R.drawable.icon_service);
                                viewHolderHelper.setText(R.id.tv_friend_type, "服务商");
                                break;
                            case Constants.USER_TYPE_TUTOR:
                                viewHolderHelper.setImageResource(R.id.iv_user_type, R.drawable.icon_teacher);
                                viewHolderHelper.setText(R.id.tv_friend_type, "导师");
                                break;
                        }
                    }

                    viewHolderHelper.setText(R.id.tv_friend_name, newsOwner.getShowName());
                } else {
                    imageView.setImageResource(R.drawable.head_image);
                    viewHolderHelper.setVisibility(R.id.iv_user_type, false);
                    viewHolderHelper.setVisibility(R.id.tv_friend_type, false);

                    viewHolderHelper.setText(R.id.tv_friend_name, R.string.app_name);
                }

                viewHolderHelper.setText(R.id.tv_friend_sign, chatSession.msg);
                viewHolderHelper.setVisibility(R.id.notice_unread, chatSession.status != 1);
            }
        }

        class NoticeAdapter extends BaseRecyclerAdapter<Notice> {

            NoticeAdapter(Activity activity) {
                super(activity, R.layout.item_notice);
            }

            @Override
            protected void setItemData(ViewHolderHelper viewHolderHelper, int position, Notice model) {
                viewHolderHelper.setText(R.id.tv_notice, model.title)
                        .setText(R.id.tv_notice_time, TimeUtils.ymdhm(model.create_time * 1000L))
                        .setVisibility(R.id.notice_unread, model.is_read ? View.INVISIBLE : View.VISIBLE);
            }
        }

    }

}
